﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Pages_ReturnCart : System.Web.UI.Page
{
    private string id;
    private int sl;
    private string returnurl = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString() != "")
        {
            id = Request.QueryString["id"].ToString();
        }
        if (Request.QueryString["ReturnUrl"] != null && Request.QueryString["ReturnUrl"].ToString() != "")
        {
            returnurl = Request.QueryString["ReturnUrl"].ToString();
        }
        cart_Click();
    }
    protected void cart_Click()
    {
        DataAccess da = new DataAccess();
        SqlCommand comm = new SqlCommand("getHangHoabyMa",da.SqlConn());
        comm.CommandType = CommandType.StoredProcedure;
        comm.Parameters.AddWithValue("@Ma",id);

        SqlDataReader drd;
        comm.Connection.Open();
        drd = comm.ExecuteReader();
        if (drd.Read())
        {
            string imgage = drd["Images"].ToString();
            string name = drd["TenHang"].ToString();
            int price = int.Parse(drd["DonGia"].ToString());
            if (Session["CartOnline"] == null)
            {
                Session["CartOnline"] = new CartOnline();
            }
            CartOnline mycart = (CartOnline)Session["CartOnline"];
            mycart.Add(id, imgage, name, price);
            Response.Redirect("Cart.aspx");
        }
        Response.Redirect(returnurl);
    }
}
